const HomePageLayoutVue = {
    getVideo_zoneList() {
        return FrequencyChannel.data.video_zoneList;
    },
    getChannel_idList() {
        return FrequencyChannel.data.channel_idList;
    },
    returnVue() {
        window.homePageLayoutVue = new Vue({
            el: "#frequencyChannelLayout",
            template: `
              <div class="tab active" id="frequencyChannelLayout">
              <h2>推送频道视频到首页</h2>
              <h3>暂时只支持推送到首页，后续调整</h3>
              <div>
                <input type="checkbox" v-model="isMainVideoListCheckbox">
                <span>指定推送</span>
                <select v-model="pushTypeSelect">
                  <option v-for="item in pushTypeList" :value="item">{{ item }}</option>
                </select>
                <select v-model="sort_typeSelect" v-if="isChannelSelect">
                  <option v-for="(item,key) in sort_typeList" :value="key">{{ item }}</option>
                </select>
                <select v-model="showListSelect">
                  <option v-for="(item,key) in showList" :value="key">{{ item }}</option>
                </select>
              </div>
              <div>
                <input type="checkbox" v-model="isIdCheckbox">id
                <button @click="findBut">查询</button>
                <button @click="okBut">确定</button>
                <hr>
              </div>
              </div>`,
            data: {
                isSetHomeStyle: LocalData.home.isSetHomeStyle(),
                isMainVideoListCheckbox: LocalData.home.isMainVideoList(),
                pushTypeSelect: "",
                pushTypeList: ["分区", "频道"],
                sort_typeSelect: "hot",
                sort_typeList: {hot: "近期热门", view: "播放最多(近30天投稿)", new: "最新投稿"},
                isIdCheckbox: false,
                //是否要显示频道的一级select
                isChannelSelect: false,
                showListSelect: 0,
                showList: {},
                videoList: []
            },
            methods: {
                findBut() {//TODO 待测试
                    const inputs = prompt("查询的类型关键词");
                    if (inputs === null) return;
                    if (inputs === "" || inputs.includes(" ")) {
                        Tip.error("请正确输入内容");
                        return;
                    }
                    const listMap = this.showList;
                    if (this.isIdCheckbox) {
                        if (inputs in listMap) {
                            this.showListSelect = inputs;
                            Tip.success(`通过ID的方式找到该值！id=${inputs} 值=${listMap[inputs]}`);
                            return;
                        }
                    } else {
                        for (let v in listMap) {//通过遍历字典中的value，该值包含于tempContent时成立
                            if (!listMap[v].includes(inputs)) continue;
                            this.showListSelect = v;
                            Tip.success(`通过value找到该值！=${inputs}`);
                            return;
                        }
                    }
                    Tip.error("未找到该值！");
                },
                okBut() {
                    const pushType = this.pushTypeSelect;
                    const showListSelect = parseInt(this.showListSelect);
                    let tip;
                    if (pushType === "分区") {
                        tip = `选择了分区${this.showList[showListSelect]} 进行指定推送 id=${showListSelect}`;
                        LocalData.setVideo_zone(showListSelect);
                    } else {
                        const temp = this.sort_typeSelect;
                        tip = `选择了${this.sort_typeList[temp]}的频道${this.showList[showListSelect]}进行指定推送 id=${showListSelect}`;
                        FrequencyChannel.setChannel_id(showListSelect);
                        FrequencyChannel.setSort_type(temp);
                    }
                    FrequencyChannel.setPushType(pushType);
                    ///TODO 频道待定处理
                    alert("已设置！\n" + tip)
                },
                replaceItBut() {
                    const temp = FrequencyChannel.getPushType();
                    if (FrequencyChannel.videoIndex <= 50 && temp === "分区") {
                        FrequencyChannel.videoIndex += 10;
                    }
                    if (temp === "分区") {
                        FrequencyChannel.loadingVideoE(FrequencyChannel.videoIndex);
                    } else {
                        FrequencyChannel.loadingVideoZE();
                    }
                }
            },
            watch: {
                isMainVideoListCheckbox(newVal) {
                    LocalData.home.setMainVideoList(newVal);
                },
                isSetHomeStyle(newBool) {
                    LocalData.home.setHomeStyle(newBool);
                },
                pushTypeSelect(newVal) {
                    if (newVal === "分区") {
                        this.showList = HomePageLayoutVue.getVideo_zoneList();
                        this.isChannelSelect = false;
                        this.showListSelect = LocalData.getVideo_zone();
                    } else {
                        this.showList = HomePageLayoutVue.getChannel_idList();
                        this.isChannelSelect = true;
                        this.showListSelect = FrequencyChannel.getChannel_id();
                        this.sort_typeSelect = FrequencyChannel.getSort_type();
                    }
                }
            },
            created() {
                this.pushTypeSelect = FrequencyChannel.getPushType();
                switch (this.pushTypeSelect) {
                    case "频道":
                        this.showList = HomePageLayoutVue.getChannel_idList();
                        this.sort_typeSelect = FrequencyChannel.getSort_type();
                        this.showListSelect = FrequencyChannel.getChannel_id();
                        this.isChannelSelect = true;
                        break;
                    default:
                        this.showList = HomePageLayoutVue.getVideo_zoneList();
                        this.showListSelect = LocalData.getVideo_zone();
                        this.sort_typeSelect = FrequencyChannel.getSort_type();
                        break;
                }
            }
        });
    }
}